<?php
Database($_SESSION['cid']);
header("content-type:text/html;charset=utf-8");
class ProjectAction extends Action{

	public function index(){
		$name=D('Company/Audience')->get_admin($_SESSION['id']);

		$rs=pageing('project',4,'',$_GET['seach'],'project_id desc','1','project_name','',"DB_MEETING");
		foreach($rs['data'] as $val){
			$val['project_startTime']=date("Y-m-d H:i",$val['project_startTime']);
			$val['project_endTime']=date("Y-m-d H:i",$val['project_endTime']);
			$val['project_leader']=D('Audience')->get_name_by_id($val['project_leader']);
			$arr[]=$val;
		}
		$rs['data']=$arr;
		$this->assign("name",$name);
		$this->assign("rs",$rs);
		$this->assign("datas",$arr);
		$this->display();
	}
//删
	public function delAct(){
		$data['time_delete']=time();
        $result = M('project','','DB_MEETING')->where(array('project_id'=>$_GET['project_id']))->save($data);
		if ($result){
			echo '{"state":1}';
		}else{
			echo '{"state":0}';
		}
    }
//改
	public function to_update(){
		$project = M('project','','DB_MEETING')->where('project_id='.$_GET['project_id'])->find();
		$this->assign('project',$project);
		$this->display();
	}

	public function uptAct(){
		$_POST['time_update']=time();
		$rs = D('Company/Audience')->save_data('project','project_id',$_POST['project_id'],$_POST);
		if($rs){
			$this->success("修改成功!");
		} else {
			$this->error("修改失败！");
		}
	}
//增
	public function addAct(){		
		if($_POST){
			$_POST['time_insert']=time();
			$_POST['project_startTime']=strtotime($_POST['project_startTime']);
			$_POST['project_endTime'] = strtotime($_POST['project_endTime']);
			$rs = D('Company/Audience')->add_data("project",$_POST);
			if($rs){
				$this->success("添加成功!",__APP__."/Project");
			} else {
				$this->error("添加失败");
			}
		}
	}
	
//查
	public function search(){
		if($_GET){
		
			$rs=pageing('project',4,'',$_GET['seach'],'project_id desc','1','project_name','',"DB_MEETING");
			foreach($rs['data'] as $val){
				$val['project_startTime']=date("Y-m-d H:i",$val['project_startTime']);
				$val['project_endTime']=date("Y-m-d H:i",$val['project_endTime']);
				$val['project_leader']=D('Audience')->get_name_by_id($val['project_leader']);
				$arr[]=$val;
			}
			$rs['data']=$arr;
		
			$this->assign("rs",$rs);
			$this->assign("datas",$arr);
			$this->display();	
		}	
	}
}	
?>
